package org.service.es.service.impl;

import io.undertow.security.idm.Account;
import lombok.RequiredArgsConstructor;
import org.dromara.easyes.core.conditions.select.LambdaEsQueryWrapper;
import org.service.es.constant.EsConstant;
import org.service.es.mapper.AccountMapper;
import org.service.es.service.AccountService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * AccountService
 *
 * @author grl
 * @date 2024/2/22
 */
@Service
@RequiredArgsConstructor
public class AccountServiceImpl implements AccountService {

    private final AccountMapper accountService;

    @Override
    public List<Account> getAll() {
        LambdaEsQueryWrapper<Account> wrapper = new LambdaEsQueryWrapper<>();
        List<Account> list = accountService.selectList(wrapper);
        return list;
    }

    @Override
    public List<Account> Query(String name) {
        LambdaEsQueryWrapper<Account> wrapper = new LambdaEsQueryWrapper<>();
        wrapper
                .eq(Account::getPrincipal,name,10.0F)
                .match(Account::getRoles,name,10.0F)
                .or()
                .match("userName.standard",name,1.0F);
        List<Account> list = accountService.selectList(wrapper);
        return list;
    }

    @Override
    public Integer save(Account account){
        return accountService.insert(account);
    }

    @Override
    public Boolean deleteIndex() {
        Boolean aBoolean = accountService.deleteIndex(EsConstant.ACCOUNT_INDEX);
        return aBoolean;
    }

    @Override
    public Boolean createIndex() {
        Boolean aBoolean = accountService.createIndex(EsConstant.ACCOUNT_INDEX);
        return aBoolean;
    }
}
